Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(driver/net): 将网络设备注册到sysfs, 添加设备类属性文件 #919

Conversation

1037827920
Copy link
Contributor

本次PR的主要修改:

  • 全部设备相关:

    • 增加Device trait的dev_parent()和set_dev_parent()方法,以及在DeviceCommonData中添加了parent字段。这个跟kobject的parent还是不一样的,这个parent主要是指设备的父设备,而kobject的parent指的是设备在sysfs中的类似父目录这样的。原先的代码是将父设备设置到了kobject的parent,然后在add_device时才通过get_device_parent获取实际kobject的parent,但是这样没有相关的字段来存储device的parent了。
    • 给大部分设备的结构体添加了类型为DeviceCommonData和KObjectCommonData的字段,我觉得这样比较好,就是给设备添加共有的字段时不用去每个实现的设备结构体添加,有点麻烦
  • virtio设备相关

  • net设备相关:

    • 创建了/sys/class/net的实例并初始化了net子系统,主要文件:driver/net/class.rs
    • 实现了register_netdevice(),将网络设备注册到sysfs中
    • 创建了net设备的属性文件,目前实现了addr_assign_type/type/address/carrier/operstate
  • kobjec相关:主要是DeviceManager,添加了class_dir_create_and_add,在get_device_parent()中被调用,主要是为了判断该设备是否为设备类,然后在其父设备下创建对应的类目录,在该类目录中创建目标为设备的符号链接。如virtio0下的net类目录创建了eth1的符号链接:
    image-20240908222024905
    对于没有父设备的设备,比如lo,fbcon,tty0等在/sys/devices/virtual下创建类目录,然后链接到设备:
    image-20240908222235570

@github-actions github-actions bot added the enhancement New feature or request label Sep 8, 2024
@fslongjin fslongjin added the A-network Area: 网络子系统 label Sep 9, 2024
Copy link
Member

@Samuka007 Samuka007 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好多attribute,没啥问题。
像是KObject的这些方法可以单独约束一条要求提供kobject引用的trait,然后其他method就可以直接在这上面调用,而不用每个结构都impl一遍了。
以及,一些Arc子trait转父trait,在较新的标准中似乎并不是能直接使用as转换的,尽管能通过编译:(E0605)。是否考虑使用intertrait的cast提供的转换?以及,这样是否会移入额外的运行时开销?

let virtio_index = VIRTIO_DEVICE_INDEX_MANAGER.alloc();
dev.set_virtio_device_index(virtio_index);
dev.set_device_name(format!("virtio{}", virtio_index.data()));
virtio_drv.probe(&dev)?;

device_manager().add_device(dev.clone() as Arc<dyn Device>)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

比如这种地方,在较新的RA版本中会报错,使用intertrait cast后可消除该报错:

Suggested change
device_manager().add_device(dev.clone() as Arc<dyn Device>)?;
device_manager().add_device(dev.cast::<dyn Device>().unwrap())?;

@Samuka007 Samuka007 merged commit 28fe4ad into DragonOS-Community:master Sep 11, 2024
8 checks passed
Samuka007 added a commit that referenced this pull request Sep 28, 2024
* 修复mprotect系统调用未正确设置vm_flags的错误 (#847)

* fix(time): modify update wall time (#836)

更改了时间子系统的update_wall_time函数,通过读取当前周期数,计算delta值进行更新,而不是通过传入delta值进行更新

* chore: 调整triagebot.toml以适应新的组织架构 (#848)

* doc: 完善README.md (#849)

* doc: 完善README.md

* chore: 更新sphinx相关配置,适应read the docs的更新 (#850)

根据read the docs在7月15日blog,进行此修改

https://about.readthedocs.com/blog/2024/07/addons-by-default/

* feat(driver/net): 实现Loopback网卡接口 (#845)

* 初步实现loopback设备

* fix: build-scripts和tools目录下的make check指定工具链版本 (#861)

* fix: tcp poll没有正确处理posix socket的listen状态的问题 (#859)

* chore: 将工具链更新到2024-07-23 (#864)

* chore: 将工具链更新到2024-07-23

* feat(fs): add eventfd syscall support (#858)

* feat(fs): add eventfd syscall support

* refactor: 删除过时的va-pa转换函数,改为统一使用MMArch (#862)

* 默认nightly-2024-07-23 & config改为config.toml (#872)

* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。 (#870)

* fix: 修复由于升级到2024-07-23工具链之后,某些机器上面内核运行一直fault的问题。

* feat(cred): 初步实现Cred (#846)

* 初步实现Cred

* 添加seteuid和setegid

* 添加cred测试程序

* 修改Cred::fscmp返回结果为CredFsCmp枚举

* 完善root用户相关信息

* fix: 修复键盘码解析器没能正确处理类似ctrl C的控制字符的问题 (#877)

* fix: 修复键盘码解析器没能正确处理类似ctrl C的控制字符的问题

* fix: 解决ntty潜在的panic问题

* ci: enable ci workflow on branches other than master (#891)

* 修复unlink、unlinkat系统调用的路径错误 (#892)

* fix: socket shutdown wrong implement (#893)

* feat: 增加tokio异步运行时支持 (#894)

* fix the EventFdFlags error

* feat: support tokio (Single thread version)

Fix deadlock issue on closing file.
Add function for PipeInode and EventFdInode.

* fix: pipe 读取/写入阻塞时,无法kill进程的问题 (#889)

* fix: 修复存在多个virtio设备时,中断号冲突的问题 (#904)

* feat: 添加gendisk抽象 (#903)

* feat: 添加gendisk抽象.

* 支持使用virtio磁盘作为根文件系统

* Update initial_kthread.rs to resolve conflict.

---------

Co-authored-by: Donkey Kane <[email protected]>

* feat(mm): 简单实现fat文件系统的文件映射 (#840)

- 添加文件映射相关接口,目前已简单实现fat文件系统的私有映射和共享映射
- 添加msync系统调用(由于当前未实现脏页自动回写,需要手动调用msync进行同步)
- 简单实现PageCache(暂时使用HashMap进行文件页号与页的映射)
- 添加新的PageFlags标志结构,原PageFlags改名为EntryFlags
- 参考linux使用protection_map映射表进行页面标志的获取
- 添加页面回收机制
- 添加页面回收内核线程
- 缺页中断使用的锁修改为irq_save; 添加脏页回写机制
- 修复do_cow_page死锁问题
- 访问非法地址时发送信号终止进程
- 修复重复插入反向vma表的错误
- 添加test_filemap文件映射测试程序

* feat: 添加对内核引导协议的抽象 (#913)

* 添加multiboot header

* head.S传参增加bootloader类型

* feat: 添加引导加载协议的抽象,并为multiboot2实现这个抽象.

* 把framebuffer的映射地址改为从early ioremap和mmio pool分配

* riscv64能运行

* fix(virtio):修复了特定virtio设备环境下中断号重复错误,以及开机内核panic的bug (#881)

* feat: 允许通过multiboot引导(直到acpi初始化报错) (#914)

* fix(mm): 修复riscv64启动时的PageFault (#915)

* 修复riscv64启动时的PageFault

* 优化代码结构

* feat(driver/net): 将网络设备注册到sysfs, 添加设备类属性文件 (#919)

* ci(docs): Build docs when push/PR to master and release version. (#935)

Signed-off-by: longjin <[email protected]>

* fix: Fix make update-submodules-by-mirror Error (#928)

* remove --init suffix in update-submodules-by-mirror

* ci: deploy documents to minio (#936)

Signed-off-by: longjin <[email protected]>

* ci: fix awscli botcore (#937)

Signed-off-by: longjin <[email protected]>

* feat(ida): IDA内部改为使用XArray实现 (#934)

目前可以记录哪些ID已经分配,支持了ID释放的功能.

Signed-off-by: longjin <[email protected]>

* doc: add commit revision to footer while build with sphinx-multiversion (#939)

Signed-off-by: longjin <[email protected]>

* doc: 添加在github上编辑的按钮,以及扩展footer (#940)

Signed-off-by: longjin <[email protected]>

* fix: sysfs ifacetrait改名

* merge net && feat(net): stream sockpairs

---------

Signed-off-by: longjin <[email protected]>
Co-authored-by: MemoryShore <[email protected]>
Co-authored-by: 黄铭涛 <[email protected]>
Co-authored-by: LoGin <[email protected]>
Co-authored-by: linfeng <[email protected]>
Co-authored-by: Jomo <[email protected]>
Co-authored-by: Chiichen <[email protected]>
Co-authored-by: Samuel Dai <[email protected]>
Co-authored-by: Donkey Kane <[email protected]>
Co-authored-by: MemoryShore <[email protected]>
Co-authored-by: 曾俊 <[email protected]>
Co-authored-by: EMasi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-network Area: 网络子系统 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants